package com.RMP
{
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import com.greensock.*;

    public class GlobalIcons extends Sprite
    {
        var btnField:TextField;
        var fadeSpeed:Number;
        var fsBtn:Sprite;
        var fieldFormat:TextFormat;
        var eIcon:Sprite;
        var myRoot:MovieClip;
        var fsIcon:Sprite;

        public function GlobalIcons(param1:MovieClip, param2:Number) : void
        {
            myRoot = param1;
            fadeSpeed = param2;
            fsBtn = new Sprite();
            fsBtn.graphics.beginFill(myRoot.hotColor, 0);
            fsBtn.graphics.drawRect(-9, -9, 39, 30);
            fsBtn.graphics.endFill();
            fsBtn.graphics.endFill();
            fsBtn.buttonMode = true;
            fsBtn.mouseChildren = false;
            fsBtn.name = "fsBtn";
            fsBtn.addEventListener(MouseEvent.MOUSE_OVER, fsOver);
            fsBtn.addEventListener(MouseEvent.MOUSE_OUT, fsOut);
            fsBtn.addEventListener(MouseEvent.CLICK, fsClick);
            addChild(fsBtn);
            fsIcon = new Sprite();
            fsIcon.graphics.beginFill(7829367, 0.5);
            fsIcon.graphics.drawRect(0, 0, 17, 1);
            fsIcon.graphics.drawRect(0, 1, 1, 12);
            fsIcon.graphics.drawRect(16, 1, 1, 12);
            fsIcon.graphics.drawRect(1, 12, 15, 1);
            fsIcon.graphics.endFill();
            fsIcon.graphics.beginFill(7829367, 1);
            fsIcon.graphics.drawRect(2, 2, 13, 1);
            fsIcon.graphics.drawRect(2, 3, 1, 8);
            fsIcon.graphics.drawRect(14, 3, 1, 8);
            fsIcon.graphics.drawRect(3, 10, 11, 1);
            fsIcon.graphics.endFill();
            fsIcon.alpha = 1;
            fsBtn.addChild(fsIcon);
            eIcon = new Sprite();
            eIcon.graphics.beginFill(7829367, 0.5);
            eIcon.graphics.drawRect(0, 0, 17, 1);
            eIcon.graphics.drawRect(0, 1, 1, 12);
            eIcon.graphics.drawRect(16, 1, 1, 12);
            eIcon.graphics.drawRect(1, 12, 15, 1);
            eIcon.graphics.endFill();
            eIcon.graphics.beginFill(7829367, 1);
            eIcon.graphics.drawRect(4, 3, 9, 1);
            eIcon.graphics.drawRect(4, 4, 1, 6);
            eIcon.graphics.drawRect(12, 4, 1, 6);
            eIcon.graphics.drawRect(5, 9, 7, 1);
            eIcon.graphics.endFill();
            eIcon.alpha = 1;
            fsBtn.addChild(eIcon);
            myRoot.stage.addEventListener(Event.RESIZE, onResizer, false, 0, true);
            doResize();
            if (myRoot.stage.displayState == StageDisplayState.FULL_SCREEN)
            {
                fsIcon.alpha = 1;
                eIcon.alpha = 0;
            }
            else
            {
                fsIcon.alpha = 0;
                eIcon.alpha = 1;
            }
            return;
        }

        function doResize() : void
        {
            return;
        }

        function fsOver(event:MouseEvent)
        {
            TweenMax.to(fsBtn, fadeSpeed, {tint:myRoot.hotColor, overwrite:true});
            if (myRoot.stage.displayState == StageDisplayState.FULL_SCREEN)
            {
                myRoot.changeToolTipText("Close Fullscreen");
                TweenMax.to(fsIcon, fadeSpeed, {alpha:0, overwrite:true});
                TweenMax.to(eIcon, fadeSpeed, {alpha:1, overwrite:true});
            }
            else
            {
                myRoot.changeToolTipText("Fullscreen");
                TweenMax.to(fsIcon, fadeSpeed, {alpha:1, overwrite:true});
                TweenMax.to(eIcon, fadeSpeed, {alpha:0, overwrite:true});
            }
            doResize();
            myRoot.showFSToolTip();
            return;
        }

        function fsOut(event:MouseEvent)
        {
            myRoot.closeToolTip();
            TweenMax.to(fsBtn, fadeSpeed, {tint:myRoot.coldColor, overwrite:true});
            if (myRoot.stage.displayState == StageDisplayState.FULL_SCREEN)
            {
                TweenMax.to(fsIcon, fadeSpeed, {alpha:1, overwrite:true});
                TweenMax.to(eIcon, fadeSpeed, {alpha:0, overwrite:true});
            }
            else
            {
                TweenMax.to(fsIcon, fadeSpeed, {alpha:0, overwrite:true});
                TweenMax.to(eIcon, fadeSpeed, {alpha:1, overwrite:true});
            }
            doResize();
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        function fsClick(event:MouseEvent)
        {
            myRoot.closeToolTip();
            if (myRoot.stage.displayState == StageDisplayState.FULL_SCREEN)
            {
                myRoot.closeFullscreen();
                fsIcon.alpha = 0;
                eIcon.alpha = 1;
            }
            else
            {
                myRoot.openFullscreen();
                fsIcon.alpha = 1;
                eIcon.alpha = 0;
            }
            return;
        }

    }
}
